package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.MemberInfo;
import com.elder.business.service.IMemberInfoService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 成员信息Controller
 * 
 * @author elder
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/business/memberInfo")
public class MemberInfoController extends BaseController
{
    @Autowired
    private IMemberInfoService memberInfoService;

    /**
     * 查询成员信息列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(String memberName,Integer pageNum,Integer pageSize) {
        return memberInfoService.getMemberList(memberName,pageNum,pageSize);
    }

    /**
     * 导出成员信息列表
     */
    @Anonymous
    @Log(title = "成员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberInfo memberInfo)
    {
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        ExcelUtil<MemberInfo> util = new ExcelUtil<MemberInfo>(MemberInfo.class);
        util.exportExcel(response, list, "成员信息数据");
    }

    /**
     * 获取成员信息详细信息
     */
    @Anonymous
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return success(memberInfoService.selectMemberInfoByMemberId(memberId));
    }

    /**
     * 新增成员信息
     */
    @Anonymous
    @Log(title = "成员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberInfo memberInfo)
    {
        return toAjax(memberInfoService.insertMemberInfo(memberInfo));
    }

    /**
     * 修改成员信息
     */
    @Anonymous
    @Log(title = "成员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberInfo memberInfo)
    {
        return toAjax(memberInfoService.updateMemberInfo(memberInfo));
    }

    /**
     * 删除成员信息
     */
    @Anonymous
    @Log(title = "成员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(memberInfoService.deleteMemberInfoByMemberIds(memberIds));
    }

    @Anonymous
    @RequestMapping("/allMemberInfo")
    public String getAllMemberInfoList(){
        return memberInfoService.getAllMemberInfoList().toJSONString();
    }

    @Anonymous
    @RequestMapping("/getNurseMember")
    public String getNurseMember(){
        return memberInfoService.getNUrseMemberList().toJSONString();
    }

    /***
     * @description 获取个人信息
     * @author zyk
     * @date 2024/4/13 11:37
     */
    @Anonymous
    @RequestMapping("/getOneself")
    public String getOneself(@NotNull Long userId, Long memberId) {
        return memberInfoService.getMemberOneselfInfo(userId).toJSONString();
    }

    @Anonymous
    @RequestMapping("/update")
    public AjaxResult update(@RequestBody MemberInfo memberInfo)
    {
        return toAjax(memberInfoService.updateMember(memberInfo));
    }
}
